<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>寄生式继承</title>
	</head>
	<body>
		<script>
			function object(obj) {
				function F() {}
				F.prototype = obj
				return new F()
			}

			function createAnother(original) {
				var clone = object(original) // 通过调用 object() 函数创建一个新对象
				clone.sayHi = function () {
					// 以某种方式来增强对象
					console.log('我是歌谣')
				}
				return clone // 返回这个对象
			}

			var person = {
				name: 'Nicholas',
				friends: ['Shelby', 'Court', 'Van'],
			}
            //调用方法
			var anotherPerson = createAnother(person)
			anotherPerson.sayHi() //"我是歌谣"

           
            //原型链继承多个实例的引用类型属性指向相同，存在篡改的可能。无法传递参数


		</script>
	</body>
</html>
